﻿using SQLite;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Wimm.Common.Entities;
using Wimm.Common.Interfaces.Repositories;
using Wimm.DAL;
using Wimm.DAL.Repositories;

namespace WIMM.DAL.Repositories
{
    public class IconRepository:SqlLightBaseRepository, IIconRepository
    {

        public IconRepository(SQLiteAsyncConnection connection)
                :base(connection)
        {
        }

        public async Task<List<Icon>> LoadAllIcons()
        {
            return await _connection.Table<Icon>().ToListAsync();
        }


        public async Task<Icon> GetById(int id)
        {
            var list = await _connection.Table<Icon>().Where(x => x.Id == id).ToListAsync();

            return list.FirstOrDefault();
        }


        public async Task<Icon> LoadCategoryIcon(int categoryId)
        {
            ExpenseCategory category = await _connection.Table<ExpenseCategory>().Where(i => i.Id == categoryId).FirstOrDefaultAsync();

            return category == null ? null : await GetById(categoryId);
        }
    }
}
